package com.example.hal.server;

import java.util.ArrayList;
import java.util.List;

import org.restlet.resource.ServerResource;

import com.googlecode.objectify.Objectify;
import com.googlecode.objectify.ObjectifyService;
import com.example.hal.model.Activite;
import static com.googlecode.objectify.ObjectifyService.ofy;

public class ActiviteController extends ServerResource implements
 ActiviteControllerInterface {
static{

	 ObjectifyService.register(Activite.class);
}

 public ActiviteController() {
 }

 @Override
 public void create(Activite activite) {
// ObjectifyService.register(Activite.class);
 //Objectify ofy = ObjectifyService.begin();

 Activite tp = new Activite();
 tp.setNom(activite.getNom());
 tp.setLogo(activite.getLogo());
 ofy().save().entity(tp).now(); 
 //ofy.put(tp);
 }

 @Override
 public Container getAllActivites() {
 Container content = null;
 //List activites = new ArrayList();
 //Objectify ofy = ObjectifyService.begin();
 
 List<Activite> activites = ofy().load().type(Activite.class).list();

 //Query<Activite> q = ofy.query(Activite.class);

//for (Activite u : q)    activites.add(u);


 content = new Container();
 content.setActivite_list(activites);
 return content;
 }
}